import requests

from api.open_account_api import OpenAccountApi
from api.reg_login_api import RegLoginApi
from common.utils import common_assert, html_util


class TestOpenAccount(object):
    def setup(self):
        # 创建session对象
        ses = requests.session()
        # 实例化封装登录模块接口请求的类
        self.reg_login_api = RegLoginApi(ses)
        # 实例化封装开户模块接口请求的类
        self.open_account_api = OpenAccountApi(ses)
    # 实名认证测试用例
    def test01_realname(self):
        # 实现登录接口
        self.reg_login_api.user_login("18743264321","qqq123")
        # 实现实名认证接口
        resp = self.open_account_api.realname("张三","450102199003078798")
        # 断言
        common_assert(resp,200,"成功")
        ##具体断言
        resp_dict = resp.json()
        assert "张**" == resp_dict.get("data").get("realname")
        assert "450****798" == resp_dict.get("data").get("card_id")


    # 开户测试用例
    def test02_open_account(self):
        # 实现登录接口
        self.reg_login_api.user_login("18743264321", "qqq123")
        # 实现开户接口
        resp = self.open_account_api.open_account()
        # 断言
        common_assert(resp,200,"form")


    # 第三方开户测试用例
    def test03_third_open_account(self):
        # 实现登录接口
        self.reg_login_api.user_login("18743264321", "qqq123")
        # 实现开户接口
        resp_open_account = self.open_account_api.open_account()
        data_list  = html_util(resp_open_account)
        url = data_list[0]
        form_dict = data_list[1]
        # 实现第三方开户接口
        resp = self.open_account_api.third_open_account(url,form_dict)
        # 断言
        assert 200 == resp.status_code
        assert "OK" in resp.text
